home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / full / nt / MSSql / I386 / sqlx86.exe / PTK / SAMPLES / OLEAUTO / LOOPBACK.RDO / LOOPRDO.SQL < prev    next >
Encoding:
Text File  |  1996-04-03  |  1.6 KB  |  55 lines

  1. /* Stored Procedure:    sp_loopback
  2. ** Description:    This sp connects back to SQL Server via an OLE Automation
  3. **        object outside SQL Server.  The OLE Automation server retrieves a
  4. **        result set from a SSQL Server table and returns it back
  5. **        to this stored procedure.
  6. **
  7. ** This sample script should be run in the context of the 'pubs' database,        
  8. **  after creating the OLE DLL file using the SqlRdo Visual Basic project        
  9. */
  10.  
  11. if exists (select * from sysobjects where id = object_id('dbo.sp_loopbackRDO') and sysstat & 0xf = 4)
  12.     drop proc sp_loopbackRDO
  13. go
  14.  
  15. create proc sp_loopbackRDO
  16.     @table_name varchar(30),
  17.     @field_name varchar(30)
  18. as
  19.     declare @pObj int, @hr int
  20.     declare @token varchar(255), @result varchar(255)
  21.  
  22.  
  23.     Print 'Sample LoopBackRDO'
  24.     Print '------------------'
  25.  
  26.     /* Create a new OLE automation object */
  27.     exec @hr=sp_OACreate 'SQLRDO.CSqlRdo', @pObj OUT
  28.  
  29.     /* Get the current client session token */
  30.     exec sp_getbindtoken @token OUT, 1
  31.  
  32.     BEGIN TRANSACTION
  33.         /* This transaction proves that the two connections to the server
  34.         ** belonging to the same client do not deadlock each other, since
  35.         ** they are 'bound' to each other; hence the redundant update statement
  36.         */
  37.         
  38.         exec ("update " + @table_name + " set " + @field_name + " = " + @field_name)
  39.  
  40.         Print ' '
  41.         /* Invoke the RdoGetData method in the CSQLRdo obj */
  42.         exec @hr=sp_OAMethod @pObj, "RdoGetData", @result OUT, @table_name, @token
  43.         if @hr <> 0
  44.         BEGIN
  45.             ROLLBACK TRANSACTION
  46.         END
  47.     COMMIT TRANSACTION
  48.  
  49.     /* Destroy the OLE Automation object */
  50.     exec sp_OADestroy @pObj
  51. go
  52.  
  53. /* Call the stored procedure created above */
  54. sp_loopbackRDO authors, state
  55. go